﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MODEL;

namespace DAL
{
    public class WorkService
    {
        /// <summary>
        /// 查询考勤记录
        /// </summary>
        /// <returns></returns>
        public static DataTable ChaXunClass()
        {
            string sql = "select*from Work";

            DataTable dt = SqlHelper.QueryMethod(sql);
            return dt;

        }
        /// <summary>
        /// 有条件的查询考勤记录
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static DataTable ChaXunClassName(string name)
        {

            string sql;
            if (name == "")
            {
                sql = "select*from Work";
            }
            else
            {
                sql = "select*from Work where W_StuCardId=@W_StuCardId";
            }
            SqlParameter[] sp =
            {
                new SqlParameter("@W_StuCardId",name)
            };

            DataTable dt = SqlHelper.QueryMethod(sql ,sp);
            return dt;
        }
        /// <summary>
        /// 打卡的方法
        /// </summary>
        /// <param name="work"></param>
        /// <returns></returns>
        public static int DaKa(Work work)
        {
            SqlParameter[] sp =
            {
                new SqlParameter("@W_State",work.W_State),
                new SqlParameter("@W_StuCardId",work.W_StuCardId),
                new SqlParameter("@W_BeiZhu",work.W_BeiZhu),
                
            };
            
            int num = SqlHelper.NoQueryMetodProc("proc_WorkAdd2",sp,CommandType.StoredProcedure);
            return num;
        }
        /// <summary>
        /// 添加考勤记录的方法
        /// </summary>
        /// <param name="work"></param>
        /// <returns></returns>
        public static int WorkAdd(Work work)
        {
            SqlParameter[] sp =
            {
                new SqlParameter("@W_Date",work.W_Date),
                new SqlParameter("@W_State",work.W_State),
                new SqlParameter("@W_Date2",work.W_Date2),
                new SqlParameter("@W_StuCardId",work.W_StuCardId),
                new SqlParameter("@W_BeiZhu",work.W_BeiZhu),

            };
            int num = SqlHelper.NoQueryMetodProc("proc_WorkAdd", sp, CommandType.StoredProcedure);
            return num;
        }
        /// <summary>
        /// 修改考勤记录的方法
        /// </summary>
        /// <param name="work"></param>
        /// <returns></returns>
        public static int WorkUpdate(Work work)
        {
            SqlParameter[] sp =
            {
                new SqlParameter("@W_Date",work.W_Date),
                 new SqlParameter("@W_Date2",work.W_Date2),
                new SqlParameter("@W_StuCardId",work.W_StuCardId),
                new SqlParameter("@W_State",work.W_State),
                new SqlParameter("@W_BeiZhu",work.W_BeiZhu),
                new SqlParameter("@W_ID",work.W_ID)
            };
            int num = SqlHelper.NoQueryMetodProc("proc_WorkUpdate", sp, CommandType.StoredProcedure);
            return num;
        }
        /// <summary>
        /// 删除考勤记录的方法
        /// </summary>
        /// <param name="work"></param>
        /// <returns></returns>
        public static int WorkDelete(Work work)
        {
            SqlParameter[] sp =
            {
             new SqlParameter("@W_ID",work.W_ID)
            };
            int num = SqlHelper.NoQueryMetodProc("proc_WorkDelete", sp, CommandType.StoredProcedure);
            return num;
        }

    }
}
